// var i;
// var $bundleConfig = require("./BundleConfig");
// var $resKeeper = require("./ResKeeper");
// var $playerDataManager = require("./PlayerDataManager");
// var $excel = require("./Excel");
// var h = cc._decorator;
// var f = h.ccclass;
// var g = h.property;
// var _ = h.inspector;
// var y = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.shuiguo1 = null;
//         t.shuiguo2 = null;
//         t.shuiguo3 = null;
//         t.putongmater = null;
//         t.zhihuimater = null;
//         t.lockNode = null;
//         t.unlockNode = null;
//         t.paizi1 = 0;
//         t.paizi2 = 0;
//         t.paizi3 = 0;
//         t.paizi1y = 0;
//         t.paizi2y = 0;
//         t.paizi3y = 0;
//         t.jiesuostate = {};
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.initData = function (e) {
//         var t = e.id - 1e3;
//         var o = e.jinjieShuiGuoId - 1e3;
//         this.initShuiGuo1(t, this.shuiguo1, 1);
//         this.initShuiGuo1(o, this.shuiguo2, 2);
//         this.initShuiGuo3(t, o, this.shuiguo3);
//         this.paizi1 = this.shuiguo1.getChildByName("paizi").x;
//         this.paizi2 = this.shuiguo2.getChildByName("paizi").x;
//         this.paizi3 = this.shuiguo3.getChildByName("paizi").x;
//         this.paizi1y = this.shuiguo1.getChildByName("paizi").y;
//         this.paizi2y = this.shuiguo2.getChildByName("paizi").y;
//         this.paizi3y = this.shuiguo3.getChildByName("paizi").y;
//     };
//     t.prototype.initShuiGuo3 = function (e, t, o) {
//         return __awaiter(this, void 0, void 0, function () {
//             var t;
//             var n;
//             var i;
//             var a;
//             var r;
//             return __generator(this, function (c) {
//                 switch (c.label) {
//                     case 0:
//                         t = o.children[0].getComponent(cc.Sprite);
//                         return [
//                             4,
//                             this._loadRes(
//                                 $bundleConfig.BundleNames.Common,
//                                 "res/player/player" + e + "_5",
//                                 cc.SpriteFrame
//                             )
//                         ];
//                     case 1:
//                         switch (
//                             ((n = c.sent()),
//                             (t.spriteFrame = n),
//                             t.setMaterial(0, this.putongmater),
//                             (i = o.getChildByName("paizi")),
//                             (a = this.paizi3),
//                             (r = this.paizi3y),
//                             (o.getChildByName("shuiguoname").getComponent(cc.Label).string = $excel.Excel.shuiguo(
//                                 e + 1e3
//                             ).newName),
//                             e)
//                         ) {
//                             case 10:
//                                 i.x = a - 20;
//                                 t.node.height = 120;
//                                 t.node.width = 50;
//                                 break;
//                             case 4:
//                                 i.x = a - 20;
//                                 t.node.height = 120;
//                                 t.node.width = 60;
//                                 break;
//                             case 8:
//                                 i.y = r - 50;
//                                 t.node.height = 60;
//                                 t.node.width = 120;
//                                 break;
//                             default:
//                                 t.node.height = 120;
//                                 t.node.width = 120;
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.initShuiGuo1 = function (e, t, o) {
//         return __awaiter(this, void 0, void 0, function () {
//             var n;
//             var i;
//             var a;
//             var r;
//             var c;
//             var u;
//             var h;
//             var f;
//             var g;
//             return __generator(this, function (s) {
//                 switch (s.label) {
//                     case 0:
//                         n = $excel.Excel.shuiguo(e + 1e3);
//                         i = t.children[1].getComponent(cc.Sprite);
//                         a = t.children[0].getComponent(cc.Label);
//                         if ((r = $playerDataManager.PlayerDataMgr.GetEquipDataById(e + 1e3)) && r.isUnLock) {
//                             i.setMaterial(0, this.putongmater);
//                             c = n.jinJieLv;
//                             r.level >= c
//                                 ? ((a.node.active = !1), (this.jiesuostate[e] = 3))
//                                 : ((a.string = "外部等级" + c + "解锁"), (this.jiesuostate[e] = 2));
//                         } else {
//                             this.jiesuostate[e] = 1;
//                             i.setMaterial(0, this.zhihuimater);
//                             a.string = "通过" + n.unLock + "章解锁";
//                         }
//                         return [
//                             4,
//                             this._loadRes(
//                                 $bundleConfig.BundleNames.Common,
//                                 "res/player/player" + e + "_4",
//                                 cc.SpriteFrame
//                             )
//                         ];
//                     case 1:
//                         switch (
//                             ((u = s.sent()),
//                             (i.spriteFrame = u),
//                             (h = t.getChildByName("paizi")),
//                             (f = 0),
//                             (g = 0),
//                             1 == o && ((f = this.paizi1), (g = this.paizi1y)),
//                             2 == o && ((f = this.paizi2), (g = this.paizi2y)),
//                             e)
//                         ) {
//                             case 10:
//                                 h.x = f - 20;
//                                 i.node.height = 120;
//                                 i.node.width = 50;
//                                 break;
//                             case 4:
//                                 h.x = f - 20;
//                                 i.node.height = 120;
//                                 i.node.width = 60;
//                                 break;
//                             case 8:
//                                 h.y = g + 30;
//                                 i.node.height = 60;
//                                 i.node.width = 120;
//                                 break;
//                             default:
//                                 i.node.height = 120;
//                                 i.node.width = 120;
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     __decorate([g(cc.Node)], t.prototype, "shuiguo1", void 0);
//     __decorate([g(cc.Node)], t.prototype, "shuiguo2", void 0);
//     __decorate([g(cc.Node)], t.prototype, "shuiguo3", void 0);
//     __decorate([g(cc.Material)], t.prototype, "putongmater", void 0);
//     __decorate([g(cc.Material)], t.prototype, "zhihuimater", void 0);
//     __decorate([g(cc.Node)], t.prototype, "lockNode", void 0);
//     __decorate([g(cc.Node)], t.prototype, "unlockNode", void 0);
//     return __decorate([f], t);
// })($resKeeper.default);
// exports.default = y;


// import { BundleNames } from './BundleConfig';
// import ResKeeper from './ResKeeper';
// import { PlayerDataMgr } from './PlayerDataManager';
// import { Excel } from './Excel';

// const { ccclass, property } = cc._decorator;

// interface IExcelShuiguo {
//     newName: string;
//     jinJieLv: number;
//     unLock: string;
// }

// interface IEquipData {
//     isUnLock: boolean;
//     level: number;
// }

// /** @class 建议类名: ShuiGuoComponent */
// @ccclass
// export default class UI_TuJianItem extends ResKeeper {
//     @property(cc.Node)
//     public shuiguo1: cc.Node | null = null;

//     @property(cc.Node)
//     public shuiguo2: cc.Node | null = null;

//     @property(cc.Node)
//     public shuiguo3: cc.Node | null = null;

//     @property(cc.Material)
//     public putongmater: cc.Material | null = null;

//     @property(cc.Material)
//     public zhihuimater: cc.Material | null = null;

//     @property(cc.Node)
//     public lockNode: cc.Node | null = null;

//     @property(cc.Node)
//     public unlockNode: cc.Node | null = null;

//     public paizi1: number = 0;
//     public paizi2: number = 0;
//     public paizi3: number = 0;
//     public paizi1y: number = 0;
//     public paizi2y: number = 0;
//     public paizi3y: number = 0;

//     public jiesuostate: { [key: number]: number } = {};

//     /**
//      * 初始化数据
//      * @param {any} data - 数据对象
//      * 建议方法名: initializeData
//      */
//     public initData(data: any): void {
//         const id = data.id - 1000;
//         const jinjieShuiGuoId = data.jinjieShuiGuoId - 1000;

//         this.initShuiGuo1(id, this.shuiguo1, 1);
//         this.initShuiGuo1(jinjieShuiGuoId, this.shuiguo2, 2);
//         this.initShuiGuo3(id, jinjieShuiGuoId, this.shuiguo3);

//         this.paizi1 = this.shuiguo1.getChildByName("paizi").x;
//         this.paizi2 = this.shuiguo2.getChildByName("paizi").x;
//         this.paizi3 = this.shuiguo3.getChildByName("paizi").x;
//         this.paizi1y = this.shuiguo1.getChildByName("paizi").y;
//         this.paizi2y = this.shuiguo2.getChildByName("paizi").y;
//         this.paizi3y = this.shuiguo3.getChildByName("paizi").y;
//     }

//     /**
//      * 初始化水果3
//      * @param {number} id - 水果ID
//      * @param {cc.Node} parent - 父节点
//      * 建议方法名: initializeShuiGuo3
//      */
//     public async initShuiGuo3(id: number, jinjieId: number, parent: cc.Node): Promise<void> {
//         const sprite: cc.Sprite = parent.children[0].getComponent(cc.Sprite);
//         const spriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/player/player${id}_5`,
//             cc.SpriteFrame
//         ) as cc.SpriteFrame;

//         sprite.spriteFrame = spriteFrame;
//         sprite.setMaterial(0, this.putongmater);

//         const paiziNode = parent.getChildByName("paizi");
//         const shuiguoNameLabel = parent.getChildByName("shuiguoname").getComponent(cc.Label) as cc.Label;
//         shuiguoNameLabel.string = Excel.shuiguo(id + 1000).newName;

//         const xPos = this.paizi3;
//         const yPos = this.paizi3y;

//         switch (id) {
//             case 10:
//                 paiziNode.x = xPos - 20;
//                 sprite.node.height = 120;
//                 sprite.node.width = 50;
//                 break;
//             case 4:
//                 paiziNode.x = xPos - 20;
//                 sprite.node.height = 120;
//                 sprite.node.width = 60;
//                 break;
//             case 8:
//                 paiziNode.y = yPos - 50;
//                 sprite.node.height = 60;
//                 sprite.node.width = 120;
//                 break;
//             default:
//                 sprite.node.height = 120;
//                 sprite.node.width = 120;
//         }
//     }

//     /**
//      * 初始化水果1
//      * @param {number} id - 水果ID
//      * @param {cc.Node} parent - 父节点
//      * @param {number} position - 位置
//      * 建议方法名: initializeShuiGuo1
//      */
//     public async initShuiGuo1(id: number, parent: cc.Node | null, position: number): Promise<void> {
//         if (!parent) {
//             return;
//         }

//         const shuiguoData: IExcelShuiguo = Excel.shuiguo(id + 1000);
//         const sprite: cc.Sprite = parent.children[1].getComponent(cc.Sprite);
//         const label: cc.Label = parent.children[0].getComponent(cc.Label);
//         const equipData: IEquipData | null = PlayerDataMgr.GetEquipDataById(id + 1000);

//         if (equipData && equipData.isUnLock) {
//             sprite.setMaterial(0, this.putongmater);
//             const unlockLevel = shuiguoData.jinJieLv;

//             if (equipData.level >= unlockLevel) {
//                 label.node.active = false;
//                 this.jiesuostate[id] = 3;
//             } else {
//                 label.string = `外部等级${unlockLevel}解锁`;
//                 this.jiesuostate[id] = 2;
//             }
//         } else {
//             this.jiesuostate[id] = 1;
//             sprite.setMaterial(0, this.zhihuimater);
//             label.string = `通过${shuiguoData.unLock}章解锁`;
//         }

//         const spriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/player/player${id}_4`,
//             cc.SpriteFrame
//         ) as cc.SpriteFrame;

//         sprite.spriteFrame = spriteFrame;

//         const paiziNode = parent.getChildByName("paizi");
//         let xPos = 0;
//         let yPos = 0;

//         if (position === 1) {
//             xPos = this.paizi1;
//             yPos = this.paizi1y;
//         } else if (position === 2) {
//             xPos = this.paizi2;
//             yPos = this.paizi2y;
//         }

//         switch (id) {
//             case 10:
//                 paiziNode.x = xPos - 20;
//                 sprite.node.height = 120;
//                 sprite.node.width = 50;
//                 break;
//             case 4:
//                 paiziNode.x = xPos - 20;
//                 sprite.node.height = 120;
//                 sprite.node.width = 60;
//                 break;
//             case 8:
//                 paiziNode.y = yPos + 30;
//                 sprite.node.height = 60;
//                 sprite.node.width = 120;
//                 break;
//             default:
//                 sprite.node.height = 120;
//                 sprite.node.width = 120;
//         }
//     }
// }

import { BundleNames } from './BundleConfig';
import ResKeeper from './ResKeeper';
import { PlayerDataMgr } from './PlayerDataManager';
import { Excel } from './Excel';

const { ccclass, property } = cc._decorator;

// 接口建议: 建议接口名: IShuiguoExcelData
interface IExcelShuiguo {
    newName: string;
    jinJieLv: number;
    unLock: string;
}

// 接口建议: 建议接口名: IEquipmentData
interface IEquipData {
    isUnLock: boolean;
    level: number;
}

/** @class 建议类名: ShuiGuoComponent */
@ccclass
export default class ViewTuJianItem extends ResKeeper {
    @property(cc.Node)
    public shuiguo1: cc.Node | null = null;

    @property(cc.Node)
    public shuiguo2: cc.Node | null = null;

    @property(cc.Node)
    public shuiguo3: cc.Node | null = null;

    @property(cc.Material)
    public putongmater: cc.Material | null = null;

    @property(cc.Material)
    public zhihuimater: cc.Material | null = null;

    @property(cc.Node)
    public lockNode: cc.Node | null = null;

    @property(cc.Node)
    public unlockNode: cc.Node | null = null;

    public paizi1: number = 0;
    public paizi2: number = 0;
    public paizi3: number = 0;
    public paizi1y: number = 0;
    public paizi2y: number = 0;
    public paizi3y: number = 0;

    public jiesuostate: { [key: number]: number } = {};

    /**
     * 初始化数据
     * @param {any} data - 数据对象
     * 建议方法名: initializeData
     */
    public initializeData(data: any): void {
        const id = data.id - 1000;
        const jinjieShuiGuoId = data.jinjieShuiGuoId - 1000;

        this.initializeShuiGuo1(id, this.shuiguo1, 1);
        this.initializeShuiGuo1(jinjieShuiGuoId, this.shuiguo2, 2);
        this.initializeShuiGuo3(id, jinjieShuiGuoId, this.shuiguo3);

        this.paizi1 = this.shuiguo1!.getChildByName("paizi")!.x;
        this.paizi2 = this.shuiguo2!.getChildByName("paizi")!.x;
        this.paizi3 = this.shuiguo3!.getChildByName("paizi")!.x;
        this.paizi1y = this.shuiguo1!.getChildByName("paizi")!.y;
        this.paizi2y = this.shuiguo2!.getChildByName("paizi")!.y;
        this.paizi3y = this.shuiguo3!.getChildByName("paizi")!.y;
    }

    /**
     * 初始化水果3
     * @param {number} id - 水果ID
     * @param {cc.Node} jinjieId - 进阶ID
     * @param {cc.Node} parent - 父节点
     * 建议方法名: initializeShuiGuo3
     */
    public async initializeShuiGuo3(id: number, jinjieId: number, parent: cc.Node): Promise<void> {
        const sprite: cc.Sprite = parent.children[0].getComponent(cc.Sprite);
        const spriteFrame = await this._loadRes(
            BundleNames.Common,
            `res/player/player${id}_5`,
            cc.SpriteFrame
        ) as cc.SpriteFrame;

        sprite.spriteFrame = spriteFrame;
        sprite.setMaterial(0, this.putongmater);

        const paiziNode = parent.getChildByName("paizi");
        const shuiguoNameLabel = parent.getChildByName("shuiguoname").getComponent(cc.Label) as cc.Label;
        shuiguoNameLabel.string = Excel.shuiguo(id + 1000).newName;

        const xPos = this.paizi3;
        const yPos = this.paizi3y;

        switch (id) {
            case 10:
                paiziNode.x = xPos - 20;
                sprite.node.height = 120;
                sprite.node.width = 50;
                break;
            case 4:
                paiziNode.x = xPos - 20;
                sprite.node.height = 120;
                sprite.node.width = 60;
                break;
            case 8:
                paiziNode.y = yPos - 50;
                sprite.node.height = 60;
                sprite.node.width = 120;
                break;
            default:
                sprite.node.height = 120;
                sprite.node.width = 120;
        }
    }

    /**
     * 初始化水果1
     * @param {number} id - 水果ID
     * @param {cc.Node | null} parent - 父节点
     * @param {number} position - 位置
     * 建议方法名: initializeShuiGuo1
     */
    public async initializeShuiGuo1(id: number, parent: cc.Node | null, position: number): Promise<void> {
        if (!parent) {
            return;
        }

        const shuiguoData: IExcelShuiguo = Excel.shuiguo(id + 1000);
        const sprite: cc.Sprite = parent.children[1].getComponent(cc.Sprite);
        const label: cc.Label = parent.children[0].getComponent(cc.Label);
        const equipData: IEquipData | null = PlayerDataMgr.getEquipDataById(id + 1000);

        if (equipData && equipData.isUnLock) {
            sprite.setMaterial(0, this.putongmater);
            const unlockLevel = shuiguoData.jinJieLv;

            if (equipData.level >= unlockLevel) {
                label.node.active = false;
                this.jiesuostate[id] = 3;
            } else {
                label.string = `外部等级${unlockLevel}解锁`;
                this.jiesuostate[id] = 2;
            }
        } else {
            this.jiesuostate[id] = 1;
            sprite.setMaterial(0, this.zhihuimater);
            label.string = `通过${shuiguoData.unLock}章解锁`;
        }

        const spriteFrame = await this._loadRes(
            BundleNames.Common,
            `res/player/player${id}_4`,
            cc.SpriteFrame
        ) as cc.SpriteFrame;

        sprite.spriteFrame = spriteFrame;

        const paiziNode = parent.getChildByName("paizi");
        let xPos = 0;
        let yPos = 0;

        if (position === 1) {
            xPos = this.paizi1;
            yPos = this.paizi1y;
        } else if (position === 2) {
            xPos = this.paizi2;
            yPos = this.paizi2y;
        }

        switch (id) {
            case 10:
                paiziNode.x = xPos - 20;
                sprite.node.height = 120;
                sprite.node.width = 50;
                break;
            case 4:
                paiziNode.x = xPos - 20;
                sprite.node.height = 120;
                sprite.node.width = 60;
                break;
            case 8:
                paiziNode.y = yPos + 30;
                sprite.node.height = 60;
                sprite.node.width = 120;
                break;
            default:
                sprite.node.height = 120;
                sprite.node.width = 120;
        }
    }
}